package com.me.jingdongshop.ui.holder;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.me.common.ui.BaseAdapterRV;
import com.me.common.ui.BaseHolderRV;
import com.me.jingdongshop.R;
import com.me.jingdongshop.model.bean.LocationList;
import com.me.jingdongshop.ui.activity.AddressListActivity;

/**
 * Created by YL on 2017/5/9.
 */
public class AddressListHolder extends BaseHolderRV<LocationList.AddressListBean> {
    private TextView tvAddressItemName;
    private TextView tvAddressItemPhone;
    private TextView tvAddressItemAddress;
    private ImageView ivAddressItemCheck;

    public AddressListHolder(Context context, ViewGroup parent, BaseAdapterRV<LocationList.AddressListBean> adapter, int itemType) {
        super(context, parent, adapter, itemType, R.layout.activity_shopcart_addresslist_item);
    }

    @Override
    public void onFindViews(View itemView) {
        tvAddressItemName = (TextView) itemView.findViewById(R.id.tv_address_item_name);
        tvAddressItemPhone = (TextView) itemView.findViewById(R.id.tv_address_item_phone);
        tvAddressItemAddress = (TextView) itemView.findViewById(R.id.tv_address_item_address);
        ivAddressItemCheck = (ImageView) itemView.findViewById(R.id.iv_address_item_check);
    }

    @Override
    protected void onRefreshView(final LocationList.AddressListBean bean, int position) {
        tvAddressItemName.setText(bean.getName());
        tvAddressItemPhone.setText(bean.getPhoneNumber());
        tvAddressItemAddress.setText(bean.getProvince() + bean.getCity() + bean.getAddressArea() + bean.getAddressDetail());
        boolean isDefault = bean.getIsDefault() == 1 ? true : false;
        if (isDefault){
            ivAddressItemCheck.setBackgroundResource(R.drawable.ischeck);
            ((AddressListActivity)context).setCurrentId(bean.getId());
        }else {
            ivAddressItemCheck.setBackgroundResource(R.drawable.pink_hollow_circle);
        }
        ivAddressItemCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ((AddressListActivity)context).setDefault(bean.getId());
            }
        });
    }

}
